package com.linkage.linkedlife.ui.activity

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.FragmentManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.clark.dingding.constants.ARouterPath
import com.google.gson.Gson
import com.gyf.immersionbar.ImmersionBar
import com.linkage.linkedlife.R
import com.linkage.linkedlife.base.BaseActivity
import com.linkage.linkedlife.base.BaseFragment
import com.linkage.linkedlife.databinding.ActivityPagelinkBinding
import com.linkage.linkedlife.model.AgentMsg
import com.linkage.linkedlife.ui.fragment.AgentWebFragment
@Route(path = ARouterPath.PageLinkActivity)
class PageLinkActivity : BaseActivity() {

    var mainBinding: ActivityPagelinkBinding? = null


   //获取单独的字符串
    @JvmField
    @Autowired(name = "url")
    var url: String? = null
   //获取一个对象
   @JvmField
   @Autowired(name = "msgData")
   var msgData: AgentMsg? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        ImmersionBar.with(this)
            .transparentStatusBar()  //透明状态栏，不写默认透明色
            .fullScreen(true)
            .statusBarColor(R.color.white)     //状态栏颜色，不写默认透明色
            .init();
        mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_pagelink)
        Log.d("url",url)
        Log.d("msgData",Gson().toJson(msgData))
//        mainBinding?.toolbarNav?.setTitle("测试")
//        initToolBar()
        var fm: FragmentManager = getSupportFragmentManager()

        var bundle: Bundle = Bundle();
        bundle.putSerializable("msgData",msgData);
        bundle.putString("url", url);


        val fragmentMain: AgentWebFragment =
            ARouter.getInstance().build(ARouterPath.AgentWebFragment)
                .navigation() as AgentWebFragment
        fragmentMain.setArguments(bundle);//数据传递到fragment中

        fm.beginTransaction()
            .add(R.id.frame_layout, fragmentMain)
            .commit()
//        var testFragment : AgentWebFragment = fm.findFragmentById(R.id.fragment_page_link) as AgentWebFragment

    }
    private fun initToolBar() {
//        setSupportActionBar(mainBinding?.toolbarNav)
//        supportActionBar!!.setDisplayShowTitleEnabled(false)
//        mainBinding?.toolbarNav?.setBackEvent(this)



    }
}